package com.keepsport.keepsportapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.keepsport.keepsportapi.dao.MallDao;
import com.keepsport.keepsportapi.dto.MallTypeDto;
import com.keepsport.keepsportapi.entity.Mall;
import com.keepsport.keepsportapi.service.intf.MallService;
import com.keepsport.keepsportapi.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * __▁▂▃▁__ ﹀ 　　 落霞与孤骛齐飞
 * 　　﹀ _▁▂▃__ 　　 秋水共长天一色
 * 　　__▁▂▁___ ﹀ ﹋ ●
 * 　　﹋ ﹀
 * 　　█▆▅▇▆▅▄▃▄▅▆▄▅▄▃▂▃▄▆▅▇▆▄▅█
 * 　　-__~~--___-▔~~__--__~~~_----__----~~~-
 *
 * @author 1212
 * @create 2022-07-01 19:49
 */
@Service
public class MallServiceImpl implements MallService {
    @Resource
    private MallDao mallDao;
    @Override
    public R selectByType(int id) {
        //校验参数
        if (id>0) {
            List<MallTypeDto> mallTypeDtos = mallDao.selectByType(id);
            if (mallTypeDtos!=null) {
                return R.ok(mallTypeDtos);
            }
        }
        return R.fail();
    }

    @Override
    public R selectAll() {
        QueryWrapper<Mall> wrapper = new QueryWrapper<>();
        List<Mall> malls = mallDao.selectList(wrapper);
        if (malls!=null) {
            return R.ok(malls);
        }
        return R.fail();
    }

    @Override
    public R selectLike0(String name) {
        QueryWrapper<MallTypeDto> wrapper = new QueryWrapper<>();

        if(name!=null && name.length()>0){
            name="%"+name+"%";
        }else {
            name=null;
        }

        return R.ok(mallDao.selectLike(name));
    }
}
